/*
 * resultTest.cc
 *
 *  Created on: Sep 17, 2012
 *      Author: shaohong
 */


#include <iostream>
#include "results.hh"

using namespace std;

int main() {
	// read some results from
	std::vector<Result> results;

	// let's first read some records until eof is met
	 // 13337C 6 6 6 5¶
	 // 71551T 1 1 1 0¶
	 // 123456 2 3 4 3¶
	// ctrl+d in linux to end the console input

	back_insert_iterator<vector<Result>> insertIt(results);

	readResults(cin, insertIt);

	// print what we have now
	printResults(cout, results.begin(), results.end());

	// find the one whose student id is "123456"
	string idToFind = "123456";
	cout << "finding " << idToFind << endl;

	vector<Result>::const_iterator itr = findResult(results.begin(), results.end(), idToFind);
	printResult(cout, itr);

	// find the one whose student is "nonExist"
	idToFind = "nonExist";
	itr = findResult(results.begin(), results.end(), idToFind);
	if (itr == results.end()) {
		cout << "didn't find student whose id is \"" << idToFind << '"'<< endl;
	}


	// remove the one whose grade is 3
	size_t grade2bRemoved = 3;
	cout << "removing records with grade " << grade2bRemoved << endl;

	removeResultIf(results, grade2bRemoved);
	printResults(cout, results.begin(), results.end());


	//now let's create a new empty vector
	std::vector<Result> backup;

	// copy existing records to new vector
	back_insert_iterator<vector<Result>> insertToBackup(backup);

	copyResults(results.begin(), results.end(), insertToBackup);

	// print new vector
	cout << "now printing backups" << endl;
	printResults(cout, backup.begin(), backup.end());

	return 0;
}
